package com.ftg.learn.util;

/**
 * @author 布衣
 */
public class R<T> {

    private Integer code;

    private String msg;

    private T data;


    public static <T> R<T> ok(T data){
        R<T> r = new R<>();
        r.setCode(Tip.OK.getCode());
        r.setMsg(Tip.OK.getMessage());
        r.setData(data);
        return r;
    }

    public static <T> R<T> build(Tip t,T data){
        R<T> r = new R<>();
        r.setCode(t.getCode());
        r.setMsg(t.getMessage());
        r.setData(data);
        return r;
    }

    public static <T> R<T> failure(){
        R<T> r = new R<>();
        r.setCode(Tip.FAIL.getCode());
        r.setMsg(Tip.FAIL.getMessage());
        r.setData(null);
        return r;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
